﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Collections.ObjectModel;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;

namespace Kokomo.Environment.Commanding
{
	/// <summary>
	/// Represents a menu item.
	/// </summary>
	/// <seealso cref="MenuCommandItemViewModel"/>
	[ContentProperty("Items")]
	public abstract class MenuItemViewModel : NotifierObject
	{
		/// <summary>
		/// Initializes a new instance of <see cref="MenuItemViewModel"/>.
		/// </summary>
		public MenuItemViewModel()
		{
			this._icon = new Lazy<Image>(this.CreateIcon);
			this.IsVisible = true;
		}

		private bool _isVisible;
		/// <summary>
		/// Gets or sets a value indicating whether the item is visible.
		/// </summary>
		public bool IsVisible
		{
			get { return this._isVisible; }
			set
			{
				this._isVisible = value;
				this.OnPropertyChanged("IsVisible");
			}
		}

		/// <summary>
		/// Gets the icon to display.
		/// </summary>
		/// <remarks>
		/// This implementation always returns <c>null</c>.
		/// </remarks>
		public virtual ImageSource IconSource { get { return null; } }
		/// <summary>
		/// Gets the text to display.
		/// </summary>
		public abstract UiString Text { get; }

		private Lazy<Image> _icon;
		/// <summary>
		/// Gets the <see cref="Image"/> to display as the icon.
		/// </summary>
		public Image Icon
		{
			get { return this._icon.Value; }
		}

		private Image CreateIcon()
		{
			ImageSource source = this.IconSource;
			if (source != null)
			{
				return new Image() { Source = source };
			}
			return null;
		}


		/// <summary>
		/// Gets the <see cref="MenuItemViewModel"/>s to display as subitems.
		/// </summary>
		/// <remarks>
		/// This implementation always returns <c>null</c>.
		/// </remarks>
		public virtual IEnumerable<MenuItemViewModel> Items { get { return null; } }
		/// <summary>
		/// Gets the <see cref="ICommand"/> to execute.
		/// </summary>
		/// <remarks>
		/// This implementation always returns <c>null</c>.
		/// </remarks>
		public virtual ICommand Command { get { return null; } }
		/// <summary>
		/// Gets the argument to pass to the command.
		/// </summary>
		/// <remarks>
		/// This implementation always returns <c>null</c>.
		/// </remarks>
		public virtual object CommandArgument { get { return null; } }
	}
}
